package net.canang.codegen.engine.domain;

import org.apache.velocity.util.StringUtils;

/**
 * todo: comment
 */
public abstract class Property {

    protected String name;
    protected String javaName;
    protected String pluralJavaName;
    protected String labelName;
    protected int size;
    protected String type;
    protected String javaType;
    protected boolean finderKey;
    protected Model model;


    public Property(Model model) {
        this.model = model;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        this.javaName = StringUtils.firstLetterCaps(name);
        this.labelName = StringUtils.removeAndHump(name);
    }

    public String getJavaName() {
        return javaName;
    }

    public void setJavaName(String javaName) {
        this.javaName = javaName;
    }

    public String getSetMethodName() {
        return "set" + javaName;
    }

    public String getGetMethodName() {
        return "get" + javaName;
    }

    public String getLabelName() {
        return labelName;
    }

    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
        if (type == "INTEGER")
            this.javaType = "Integer";
        if (type == "LONG")
            this.javaType = "Long";
        if (type == "STRING")
            this.javaType = "String";
        if (type == "DATE")
            this.javaType = "Date";
        if (type == "STRING_ENUM")
            this.javaType = getModel().getDomain().getPrefix() + javaName + "Enum";
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public boolean isFinderKey() {
        return finderKey;
    }

    public void setFinderKey(boolean finderKey) {
        this.finderKey = finderKey;
    }

    public Model getModel() {
        return model;
    }

    public void setModel(Model model) {
        this.model = model;
    }

    public String getPluralJavaName() {
        return pluralJavaName;
    }

    public void setPluralJavaName(String pluralJavaName) {
        this.pluralJavaName = pluralJavaName;
    }
}
